package com.qf.mvc2203.controller;

import com.qf.mvc2203.entity.User;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Date;

@Controller
@RequestMapping("/param")
public class ParamController {
    /*演示普通参数收参
     * 注意：如果是日期类型收参，需要用斜线分割年月日，直接使用Date类型接收
     *  字符串类型用注解转换：@DateTimeFormat(pattern ="yyyy-MM-dd HH:mm:ss" )
     * */
    @RequestMapping("/test1")
    public String test1(Integer id, String name, Boolean gender, Date birth) {
        /*接收参数并打印*/
        System.out.println(id);
        System.out.println(name);
        System.out.println(gender);
        System.out.println(birth);
        return "/hi.html";
    }

    /*
     * 实体收参
     * */
    @RequestMapping("/test2")
    public String test2(User user) {
        System.out.println(user);
        return "/hi.html";
    }

    /*
     * 数组收参
     * */
    @RequestMapping("/test3")
    public String test3(String[] hobby) {
        for (String s : hobby) {
            System.out.println(s);
        }
        return "/hi.html";
    }

    /*
     * 数组收参
     * */
    @RequestMapping("/test4")
    public String test4(User user) {
        System.out.println(user);
        for (String s : user.getHobby()) {
            System.out.println(s);
        }
        return "/hi.html";
    }
    /*
     * 路径收参
     * */
    @RequestMapping("/get/{id}")
    public String test5(@PathVariable("id") Integer id) {
        System.out.println(id);
        return "/hi.html";
    }
    /*
     * 多级路径收参
     * */
    @RequestMapping("/get/{id}/{name}")
    public String test6(@PathVariable("id") Integer id, @PathVariable("name") String name) {
        System.out.println(id);
        System.out.println(name);
        return "/hi.html";
    }
}














